import {homeMethod} from '@/utils/models/index.js'
const crudMethod = new homeMethod();
export default {
  data() {
    return{
      telImg: require('@/assets/images/tel.png'),
      logo: require('@/assets/images/logo0.png'),
      aliReportImg: require('@/assets/images/TB1G.gif'),
      aliReportImg1: require('@/assets/images/TB1.png'),
      ewm: require('@/assets/images/ewm.jpg'),
      down: require('@/assets/images/down.png'),
      menuBtn: require('@/assets/images/menu.png'),
      productLoad: false,
      productData: [],
      serveLoad: false,
      serveData: [],
      solutionLoad: false,
      solutionData: [],
      articleLoad: false,
      articleData: [],
      partnerLoad: false,
      partnerData: [],
      dictionaryLoad: false,
      dictionaryData: [],
      curId: 'Home',
      isShow: false,
      headData: [
        { value: 'Home', label: '首页', path: '/home'},
        { value: 'Product', label: '产品', path: '/product', detail: 'ProductDetail'},
        { value: 'Serve', label: '服务', path: '/serve'},
        { value: 'Case', label: '案例', path: '/case'},
        { value: 'About', label: '关于朔悦', path: '/about'},
      ]
    }
  },
  created() {
    this.curId = this.$route.name
    this.getProducts()
    this.getServes()
    this.getSolutions()
  },
  methods: {
    handleMask() {
      this.isShow = !this.isShow
    },
    goDatas(link) {
      this.isShow = false
      if(this.curId === link.value && (this.curId === 'Product' || this.curId === 'Serve')) {
        this.$emit('goDatas')
      } else if(link.value=== 'Product' || link.value === 'Serve'){

      } else{
        this.$router.push({
          path: link.path
        });
      }
    },
    goDetails(link, val) {
      this.isShow = false
      if(val === this.curId) {
        this.$emit('goDetails', link)
      } else if(val === 'ProductDetail') {
        let path = link.productName === '报表平台' ? '/product/report' :
            link.productName === '数据大屏' ? '/product/daping' :
            link.productName === '数据集算' ? '/product/dataprocess' : '/product-detail'
        this.$router.push({
          path: path,
          query:{
            id: link.productId
          }
        });
      } else{
        let path = val === 'ProductDetail' ? '/product-detail' : val === 'Serve' ? '/serve' : '/solution-detail'
        let id = val === 'ProductDetail' ? link.productId : val === 'Serve' ? link.serveId : link.solutionId
        this.$router.push({
          path: path,
          query:{
            id: id
          }
        });
      }
    },
    // 产品
    getProducts () {
      let _this = this
      _this.productLoad = true
      crudMethod.getProduct().then((res) => {
        _this.productLoad = false
        let {msg, code, data} = res;
        data.data.forEach((item,i) => {
          item.productName = i === 0 ? '报表平台' : i === 1 ? '数据大屏' : i === 2 ? '数据集算' : item.productName
          item.productBannerImg = item.productBannerImg ? _this.baseURL + item.productBannerImg : ''
          item.productMinImg = item.productMinImg ? item.productMinImg.split(',') : []
          item.productMinImg = item.productMinImg.map(child => _this.baseURL + child)
        })
        _this.productData = data.data
      })
    },
    // 软件服务
    getServes () {
      let _this = this
      _this.serveLoad = true
      crudMethod.getServe().then((res) => {
        _this.serveLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.serveMinImg = item.serveMinImg ? item.serveMinImg.split(',') : []
          item.serveMinImg = item.serveMinImg.map((child) => {
            return _this.baseURL + child
          })
        })
        _this.serveData = data.data
      })
    },
    // 解决方案
    getSolutions () {
      let _this = this
      _this.solutionLoad = true
      crudMethod.getSolution().then((res) => {
        _this.solutionLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.solutionMinImg = item.solutionMinImg ? _this.baseURL + item.solutionMinImg : ''
          item.solutionSilhouetteImg = item.solutionSilhouetteImg ? _this.baseURL + item.solutionSilhouetteImg : ''
        })
        _this.solutionData = data.data
      })
    },
  }
}
